<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../") ; }
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../../include/module_absences.php") ;
 Include ("../include/config.inc") ;
 Include ("../include/absences.cfg") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 $rep_themes = "../../images/themes/" ;
 Include ($rep_themes."config.inc") ;
 $param_theme ["nom_repertoire"] = $themes [$themes [0][1]][1] ;
 $param_theme ["fichier_config"] = $themes [$themes [0][1]][2] ;
 Include ($rep_themes.$param_theme ["nom_repertoire"]."/".$param_theme ["fichier_config"]) ;
 
 $valider = var_courante ("valider", 0, null) ;
 $creation = var_courante ("creation", 0, null) ;
 $id_abs_note = var_courante ("id_abs_note", 0, 0) ;
 $texte = var_courante ("texte", 0, "") ;
 $id_eleve = var_courante ("id_eleve", 0, 0) ;
 $repere1 = var_courante ("repere1", 0, "") ;
 $repere2 = var_courante ("repere2", 0, "") ;
 $menu = var_courante ("menu", 0, null) ;
 $retour = var_courante ("retour", 0, null) ;
 $id_classe = var_courante ("id_classe", 0, 0) ;
 $date1 = var_courante ("date1", 0, null) ;
 $date2 = var_courante ("date2", 0, null) ;
 $semaine = var_courante ("semaine", 0, null) ;
 
 If (IsSet ($valider))
  {
   If ($valider == "VaLiDeR")
    {
     If ($creation == 0)
      {
       // Mise a jour
       $requete = "UPDATE abs_notes SET texte='".filtrage ($texte)."' WHERE id_abs_note='".$id_abs_note."' LIMIT 1" ;
      }
     Else
      {
       // Nouvelle note
       $requete = "INSERT INTO abs_notes (id_abs_note,eleve,repere1,repere2,texte) VALUES ('','".$id_eleve."','".$repere1."','".$repere2."','".filtrage ($texte)."')" ;
      }
     $ok = SQL_commande ($requete, $id_sql) ;
     //echo $requete ;
     Echo "<HTML><BODY><SCRIPT> window.open(\"./module_absence.php?menu=".$menu."&retour=".$retour."&id_eleve=".$id_eleve."&id_classe=".$id_classe."&date1=".$date1."&date2=".$date2."&semaine=".$semaine."\",\"travail_affichage\") ; window.close() </SCRIPT></BODY></HTML>" ;
     Exit ;
    }
  }
 
 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 
 
 Echo "<html><head>" ;
 entete_html ("Garennes - Module absences - M&eacute;mo", "", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 Echo "</head>" ;
 
 // Recherche de l'eleve
 $resultats = SQL_commande ("SELECT * FROM eleves WHERE id_eleve='".$id_eleve."' LIMIT 1", $id_sql) ;
 $ligne = SQL_tableau_associatif ($resultats, "") ;
 
 Echo "<BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\">" ;
 Echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">" ;
 Echo "<TR>" ;
 Echo "<TD></TD>" ;
 Echo "<TD WIDTH=\"100%\" ALIGN=\"CENTER\">Notes&nbsp;sur&nbsp;l'&eacute;l&egrave;ve&nbsp;<FONT COLOR=\"#0000FF\">".$ligne ["nom"]."&nbsp;<I>".prenom_eleve ($ligne ["prenoms"])."</I></FONT></TD>" ;
 Echo "<TD><A onClick=\"javascript:window.close()\" BORDER=\"0\"><IMG SRC=\"../../images/quitter.png\" BORDER=\"0\"></A></TD>" ;
 Echo "</TR>" ;
 Echo "</TABLE>" ;
 
 // Recherche de la note si existe
 $notes = memo_notes ($id_eleve, $ligne ["repere1"], $ligne ["repere2"]) ;
 
 If ($edition == 1)
  {
   Echo "<FORM ACTION=\"".$_SERVER ["PHP_SELF"]."\" NAME=\"abs_note\" METHOD=\"POST\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"creation\" VALUE=\"".$creation."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"date1\" VALUE=\"".$date1."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"date2\" VALUE=\"".$date2."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"semaine\" VALUE=\"".$semaine."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"menu\" VALUE=\"".$menu."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"retour\" VALUE=\"".$retour."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_classe\" VALUE=\"".$id_classe."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_abs_note\" VALUE=\"".$notes [0]."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_eleve\" VALUE=\"".$id_eleve."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"repere1\" VALUE=\"".$ligne ["repere1"]."\">" ;
   Echo "<INPUT TYPE=\"HIDDEN\" NAME=\"repere2\" VALUE=\"".$ligne ["repere2"]."\">" ;
   Echo "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" ALIGN=\"CENTER\">" ;
   Echo "<TR><TD COLSPAN=\"2\" WIDTH=\"".($largeur_fenetre_edition+50)."\">" ;
   Echo "<TABLE BORDER=\"0\"  WIDTH=\"100%\" CELLPADDING=\"0\" CELLSPACING=\"0\" BGCOLOR=\"".$theme [0][3]."\" STYLE=\"border:1px #000000 solid;border-collapse:collapse\">" ;
   Echo "<TR><TD>".active_editeur ($hauteur_fenetre_edition, $largeur_fenetre_edition+50, "Simple", $param_theme ["nom_repertoire"], $notes [1])."</TD></TR>" ;
   Echo "</TABLE>" ;
   /*
   Echo "<TD COLSPAN=\"3\" vALIGN=\"top\"><TEXTAREA NAME=\"texte\" COLS=\"".$nombre_colonnes_notes."\" ROWS=\"".$nombre_lignes_notes."\">".Str_Replace ("\\'", "'", $notes [1])."</TEXTAREA></TD>" ;
   Echo "<TD vALIGN=\"top\">" ;
   // Recherche de la typographie
   $resultats = SQL_commande ("SELECT a.nom AS nom_type,b.* FROM abs_types_typo a,abs_typos b WHERE a.id_abs_type_typo=b.id_abs_type_typo ORDER BY a.nom,b.nom", $id_sql) ;
   $ligne = SQL_tableau_associatif ($resultats, "") ;
   Echo "<TABLE BORDER=\"1\" CELLPADDING=\"0\" CELLSPACING=\"0\">" ;
   Echo "<TR><TD>&nbsp;</TD></TR>" ;
   Echo "<TR><TD>&nbsp;" ;
   Echo "<A onClick=\"javascript:document.abs_note.texte.value=document.abs_note.texte.value+'".$ligne ["code_debut"]." ".$ligne ["code_fin"]."'\">" ;
   If ($ligne ["image"]) { Echo "<IMG SRC=\"../images/absences/".$ligne ["image"]."\" BORDER=\"0\">" ; }
   Else { Echo Str_Replace (" ", "&nbsp;", $ligne ["nom"]) ; }
   Echo "</A>" ;
   $tt = $ligne ["id_abs_type_typo"] ;
   $compteur = 1 ;
   For ($i = 1 ; $i < SQL_nbr_lignes ($resultats) ; $i++)
    {
     $ligne = SQL_tableau_associatif ($resultats, "") ;
     If ($ligne ["id_abs_type_typo"] != $tt)
      {
       Echo "</TD></TR><TR><TD>&nbsp;</TD></TR><TR><TD>&nbsp;" ;
       $tt = $ligne ["id_abs_type_typo"] ;
       $compteur = 0 ;
      }
     ElseIf ($compteur%4 == 0) { Echo "</TD></TR><TR><TD>&nbsp;" ; }
     Echo "<A onClick=\"javascript:document.abs_note.texte.value=document.abs_note.texte.value+'".$ligne ["code_debut"]." ".$ligne ["code_fin"]."'\">" ;
     If ($ligne ["image"]) { Echo "<IMG SRC=\"../images/absences/".$ligne ["image"]."\" BORDER=\"0\">" ; }
     Else { Echo Str_Replace (" ", "&nbsp;", $ligne ["nom"]) ; }
     $compteur++ ;
    }
   Echo "</TD></TR>" ;
   Echo "<TR><TD>&nbsp;</TD></TR>" ;
   Echo "</TABLE>" ;
   Echo "</TD>" ;
   Echo "</TR>" ;
   */
   Echo "</TD></TR>" ;
   Echo "<TR>" ;
   Echo "<TD ALIGN=\"RIGHT\" WIDTH=\"".($largeur_fenetre_edition/2+30)."\"><INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/valider.png\" NAME=\"valider\" VALUE=\"VaLiDeR\"></TD>" ;
   Echo "</FORM>" ;
   Echo "<TD ALIGN=\"RIGHT\"><FORM><INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/annuler.png\" NAME=\"annuler\" VALUE=\"AnNuLeR\" onClick=\"javascript:window.close()\"></FORM></TD>" ;
   Echo "</TR>" ;
   Echo "</TABLE>" ;
  }
 Else
  {
   Echo "<br>" ;
   Echo "<center>&Eacute;dition m&eacute;mo-note non autoris&eacute;es</center>" ;
   If ($notes [0] > 0)
    {
     Echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr><td valign=\"top\">".formattage_texte ($notes [1])."</td></tr></table>" ;
    }
   Else
    {
     Echo "<br><br><center>Aucune note pour cet &eacute;l&egrave;ve.</center>" ;
    }
  }
 Echo "</BODY>" ;
 Echo "</HTML>" ;
?>